package com.handinglian.employee.service.impl;

import com.handinglian.common.utils.FastJsonUtil;
import com.handinglian.employee.dto.UserTagDto;
import com.handinglian.employee.entity.UserTag;
import com.handinglian.employee.mapper.UserTagMapper;
import com.handinglian.employee.param.UserTagCreateParam;
import com.handinglian.employee.service.UserTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Date;
import java.util.List;

@Service("userTagService")
public class UserTagServiceImpl implements UserTagService {
    @Autowired
    private UserTagMapper userTagMapper;

    @Override
    @Transactional
    public int createUserTag(UserTagCreateParam userTagCreateParam) {
        UserTag userTag = new UserTag();
        userTag.setUserId(userTagCreateParam.getUserId());
        userTag.setTagName(userTagCreateParam.getTagName());
        userTag.setCreateTime(new Date());
        return userTagMapper.insertSelective(userTag);
    }


    @Override
    @Transactional
    public int deleteUserTag(Integer userTagId) {
        return userTagMapper.deleteByPrimaryKey(userTagId);
    }

    @Override
    public List<UserTagDto> inquireUserTagList(Integer userId) {
        return FastJsonUtil.ListToList(userTagMapper.findByUserId(userId), UserTagDto.class);
    }

    @Override
    public List<UserTagDto> inquireUserTagList(Collection<Integer> userTagIds) {
        return FastJsonUtil.ListToList(userTagMapper.findByUserTagIdIn(userTagIds), UserTagDto.class);
    }

    @Override
    @Transactional
    public int createBatch(List<UserTag> list) {
        return userTagMapper.batchInsert(list);
    }
}
